{extend name="admin/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
{/block}
{block name="right_tab"} 
<li><a class="nscs-table-handle_green" href="javascript:;" onclick="add_user();"><i class="fa fa-plus-circle"></i>&nbsp;添加会员</a></li>
{/block}
{block name="main"}
<div class="mod-table">
	<div class="mod-table-head">
	
		<table class="mytable">
			<tr>
				<th width="10%" style="text-align: left;">
					<a class="btn btn-small fun-a" href="javascript:batchDelete()">批量删除</a>
				</th>
				<th style="width:37%">
					<select style="width:130px;color: #999;" id="level_name">
						<option value ="-1">请选择会员等级</option>
						{volist name="level_list['data']" id="vo"}
						<option value ="{$vo.level_id}">{$vo.level_name}</option>
						{/volist}
					</select>
				</th>
				<th width="40%">
					<input type="text" id = 'search_text' placeholder="输入手机号/邮箱/会员昵称" />
					<input type="button" onclick="searchData()" value="搜索" />
					<input type="button" onclick="dataExcel()" value="导出数据" />	
				</th>
			</tr>
		</table>
		<div class="style0list">
			<table>
				<thead>
					<tr align="center">
						<th><label style="margin-left: 5px;"><input type="checkbox" onclick="CheckAll(this)"></label></th>
						<th class="tal" style="width: 30%;">会员</th>
						<th class="tal">会员等级</th> 
						<th class="tal">积分</th>
						<th class="tal">账户余额</th>
						<th class="tal">注册&登录</th>
						<th>状态</th>
						<th style="width: 17%;">操作</th>
					</tr>
				</thead>
				<tbody id="productTbody"></tbody>
			</table>
		</div>
	</div>
	
</div>

<!-- 余额调整 -->
<div class="modal fade hide" id="recharge_balance" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">调整余额</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table>
						<tr>
							<td>当前余额</td>
							<td colspan='3' id="current_balance"></td>
						</tr>
						<tr>
							<td>调整金额</td>
							<td colspan='3' id="time"><input type="number" id="balance" class="balance" />增加或减少</td>
						</tr>
						<tr>
							<td>备注</td>
							<td colspan='3' id="time"><textarea id="remark_balance"></textarea></td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<input type="hidden" id="balance_id" />
				<button class="btn btn-info" onclick="addAccount(2)" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<!-- 积分调整 -->
<div class="modal fade hide" id="recharge_point" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">调整积分</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table>
						<tr>
							<td>当前积分</td>
							<td colspan='3' id="current_point"></td>
						</tr>
						<tr>
							<td>调整积分</td>
							<td colspan='3' id="time"><input type="number" id="point" class="point">增加或减少</td>
						</tr>
						<tr>
							<td>备注</td>
							<td colspan='3' id="time"><textarea id="remark_point"></textarea></td>
						</tr>
					</table>
					
				</div>
			</div>
			<div class="modal-footer">
				<input type="hidden" id="point_id" />
				<button class="btn btn-info" onclick="addAccount(1)" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<!-- 添加会员 -->
<div class="modal fade hide" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">添加会员</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%;"><span class="required">*</span>用户名</td>
							<td colspan='3'>
								<input type="text" id="username"/>
								<span id="usernameyz"></span>
								<input type="hidden" value="不存在" id="isset_username"/>
							</td>
						</tr>
						<tr>
							<td><span class="required">*</span>登录密码</td>
							<td colspan='3'><input type="password" id="password" class="balance"></td>
						</tr>
						<tr>
							<td style="width:22%;">昵称</td>
							<td colspan='3'>
								<input type="text" id="nickname"/>
							</td>
						</tr>
						<tr>
							<td>会员等级</td>
							<td colspan='3' style="padding-bottom: 0;">
								<p>
									{if $level_list['data']}
									<select id="member_level">
										{foreach name="level_list['data']" item="vo"}
										<option value="{$vo.level_id}">{$vo.level_name}</option>
										{/foreach}
									</select>
									{else/}
									<span>暂无会员等级分类</span>
									{/if}
								</p>
							</td>
						</tr>
						<tr>
							<td>手机号码</td>
							<td colspan='3'><input type="text" id="telephone"/></td>
						</tr>
						<tr>
							<td>邮箱地址</td>
							<td colspan='3'><input type="text" id="member_email"/></td>
						</tr>
						<tr>
							<td>性别</td>
							<td><label><input type="radio" checked="checked" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
						</tr>
						<tr>
							<td>账户状态</td>
							<td><label><input type="radio" checked="checked" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<button class="btn btn-info" onclick="addUser()" id="butSubmit"  style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<input type="hidden" id="modify_uid"/>
<!-- 修改会员 -->
<div class="modal fade hide" id="modify_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog" >
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">编辑会员</h4>
			</div>
			<div class="modal-body" style="min-height: 360px;">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr style="height: 32px;">
							<td style="width:20%"><span class="required">*</span>用户名</td>
							<td colspan='3'>
								<span id="modify_username"></span>
								<span id="modify_usernameyz"></span>
								<input type="hidden" value="不存在" id="modify_isset_username"/>
							</td>
						</tr>
						<tr>
							<td style="width:20%">昵称</td>
							<td colspan='3'><input type="text" id="modify_nickname"/></td>
						</tr>
						<tr>
							<td>会员等级</td>
							<td colspan='3' style="padding-bottom: 0;">
								<p>
									{if $level_list['data']}
									<select id="modify_member_level">
										{foreach name="level_list['data']" item="vo"}
										<option value="{$vo.level_id}">{$vo.level_name}</option>
										{/foreach}
									</select>
									{else/}
									<span>暂无会员等级分类</span>
									{/if}
								</p>
							</td>
						</tr>
						<tr>
							<td>手机号码</td>
							<td colspan='3'><input type="text" id="modify_telephone" value=""/></td>
						</tr>
						<tr>
							<td>邮箱地址</td>
							<td colspan='3'><input type="text" id="modify_member_email"/></td>
						</tr>
						<tr>
							<td>性别</td>
							<td id="sex"><label><input type="radio" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
						</tr>
						<tr>
							<td>账户状态</td>
							<td id="status"><label><input type="radio" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<input type="hidden" id="modify_username_hidden" />
				<button class="btn btn-info" onclick="modifyUser()" id="butSubmit"  style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>

<!-- 修改会员 -->
<div class="modal fade hide" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">重置密码</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%">密码</td>
							<td colspan='3'><input type="text" id="modify_passwords"/></td>
						</tr>
					</table>
				</div>
			</div>
			
			<div class="modal-footer">
				<input type="hidden" id="modify_userid" />
				<button class="btn btn-info" onclick="modifypassword()" id="butSubmit"  style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
	
</div>


{/block}
{block name="script"}
<script type="text/javascript">
var window_height = $(window).height();//浏览器高度
var add_user_height = $("#add_user").height();//实际弹出框高度
if(add_user_height>window_height){
	//当电脑分辨率小时（笔记本电脑），给弹出框设置滚动
	$("#add_user").css({
		"height" : $(window).height()-100,
		"overflow-y" : "scroll",
		"top" : "10%"
	});
	$("#modify_user").css({
		"height" : $(window).height()-100,
		"overflow-y" : "scroll",
		"top" : "10%"
	});
	
}
	function LoadingInfo(page_index) {
		var search_text = $("#search_text").val();
		var levelid = $("#level_name").val();
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/memberlist')}",
			data : {
				"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text,"levelid":levelid
			},
			success : function(data) {
				var html = '';
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						html += '<tr align="center">';
						html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data["data"][i]["uid"]+'" ></label></div></td>';
						html += '<td align="left">';
							
						if(data["data"][i]["user_headimg"] ==""){
							html += '<img src="__STATIC__/images/default_user_portrait.gif" class="head-portrait" />';
							if(data["data"][i]["user_name"] == '' || data["data"][i]["user_name"] == null){
								html+='用户名:'+'--'+'<br/>';
							}else{
								html+='用户名:'+data["data"][i]["user_name"] +'<br/>';
							}
							if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
								if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+'--';
								} else {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
								}
							} else {
								if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
								} else {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
								}
							}
						}else{
							html += '<img src="__UPLOAD__/'+data["data"][i]["user_headimg"]+'" class="head-portrait" />';
							if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
								if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+'--';
								} else {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
								}
							} else {
								if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
								} else {
									html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
								}
							}
						}
						html += '</td>';
						if(data["data"][i]["level_name"]==null || data["data"][i]["level_name"]==undefined){
							html += '<td class="tal">--</td>';
						}else{
							html += '<td class="tal">' + data["data"][i]["level_name"] + '</td>';
						}
						html += '<td class="tal">' + data["data"][i]["point"] + '</td>';
						html += '<td class="tal">'+'¥'+ data["data"][i]["balance"] +'</td>';
						html += '<td class="tal">' +'注册时间 : '+ timeStampTurnTime(data["data"][i]["reg_time"]) +'<br>'+'最后登录 : '+ timeStampTurnTime(data["data"][i]["current_login_time"])+'</td>';
						html += data["data"][i]["user_status"] == 0 ? '<td style="color:red;">锁定</td>' : '<td style="color:green;">正常</td>';
						html += '<td><a href="'+__URL('ADMIN_MAIN/member/pointdetail?member_id='+ data['data'][i]['uid'])+'">积分明细</a>&nbsp;&nbsp;';
						html += '<a href="'+__URL('ADMIN_MAIN/member/accountdetail?member_id='+ data['data'][i]['uid'])+'">余额明细</a><br/>';
						html += '<a onclick="recharge_point('+ data["data"][i]["uid"]+','+ data["data"][i]["point"] +')">积分调整</a>&nbsp;&nbsp;';
						html += '<a onclick="recharge_balance('+ data["data"][i]["uid"]+','+data["data"][i]["balance"]+')">余额调整</a><br/>';
						
						if(data["data"][i]["is_system"] != 1){
							if(data["data"][i]["user_status"] == 0){
								html += '<a onclick="unlockuser('+ data["data"][i]["uid"]+')">设置解锁&nbsp;&nbsp;&nbsp;</a>';
							}else{
								html += '<a onclick="lockuser('+ data["data"][i]["uid"]+')">设置锁定&nbsp;&nbsp;&nbsp;</a>';
							}
							html += '<a onclick="modify_password('+ data["data"][i]["uid"]+')">重置密码</a><br/>';
							
							html += '<a onclick="modify_user('+ data["data"][i]["uid"]+')">修改</a>&nbsp;&nbsp;<a onclick="delete_user('+ data["data"][i]["uid"]+')">删除</a><br/>';
							
						}
						html += '</td>'
						html += '</tr>';
					}
				} else {
					html += '<tr align="center"><th colspan="9">暂无符合条件的数据记录</th></tr>';
				}
				$(".style0list tbody").html(html);
				initPageData(data["page_count"],data['data'].length,data['total_count']);
				$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
			}
		});
	}
	//全选
	function CheckAll(event){
		var checked = event.checked;
		$(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
	}

	function searchData(){
		LoadingInfo(1);
	}
	//锁定会员
	function lockuser(uid){
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/memberlock')}",
			data : { "id" : uid },
			success : function(data) {
				if (data["code"] > 0) {
					LoadingInfo(getCurrentIndex(uid,'#productTbody'));
					showTip(data['message'],'success');
				}else{
					showTip(data['message'],'error');
				}
			}
		});
	}
	//解锁会员
	function unlockuser(uid){
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/memberunlock')}",
			data : { "id" : uid },
			success : function(data) {
				if (data["code"] > 0) {
					LoadingInfo(getCurrentIndex(uid,'#productTbody'));
					showTip(data['message'],'success');
				}else{
					showTip(data['message'],'error');
				}
			}
		});
	}
	//添加会员弹出
	function add_user(){
		$("#add_user").modal("show");
	}
	
	//积分充值
	function recharge_point(uid,point){
		$("#recharge_point").modal("show");
		$("#point_id").val(uid);
		$("#current_point").text(point);
	}
	//余额充值
	function recharge_balance(uid,balance){
		$("#recharge_balance").modal("show");
		$("#balance_id").val(uid);
		$("#current_balance").text(balance);
	}
	//充值
	function addAccount(type){
		if(type == 1){
			var id = $("#point_id").val();
			var num = $("#point").val();
			var current_point = $("#current_point").text();
			var point = (parseInt(current_point) + parseInt(num));
			if(num == ''){
				showTip('积分不能为空','warning');
				return false;
			}
			var text = $("#remark_point").val();
			if(parseInt(point) < 0){
				showTip('积分不能为负数','warning');
				return false;
			}
		}else{
			var id = $("#balance_id").val();
			var num = $("#balance").val();
			var current_balance = $("#current_balance").text();
			var balance = (parseInt(current_balance) + parseInt(num));
			if(num == ''){
				showTip('余额不能为空','warning');
				return false;
			}
			var text = $("#remark_balance").val();
			if(parseInt(balance) < 0){
				showTip('余额不能为负数','warning');
				return false;
			}
		}
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/addmemberaccount')}",
			data : {
				"id" : id,
				"type" : type,
				"num" : num,
				"text" : text
			},
			success : function(data) {
				if (data["code"] > 0) {
					LoadingInfo(getCurrentIndex(id,'#productTbody'));
					showTip(data['message'],'success');
				}else{
					showTip(data['message'],'error');
				}
			}
		});
	}
	//检测输入的会员用户名是否已经存在
	$("#username").blur(function(){
		var username = $(this).val();
		$(this).css("border","1px solid #ccc");
		$("#usernameyz").css("color","black").text("");
		$("#isset_username").attr("value","不存在");
		if(username === $("#modify_username_hidden").val()){
 			return;
 		}
		checkUserName(username);
	});
	
	function checkUserName(username){
		var flag = true;
		$.ajax({
			type: "GET",
			url: "{:__URL('ADMIN_MAIN/member/check_username')}",
			async : false,
			data: {"username":username},
			success: function(data){
				if(data){
					flag = false;
					$("#username").css("border","1px solid red");
					$("#usernameyz").css("color","red").text("用户名已存在");
					$("#isset_username").attr("value","存在");
				}
			} 
		});
		return flag;
	}

	//添加会员
	function addUser(){
		var username = $("#username").val();
		var nickname = $("#nickname").val();
		var password = $("#password").val();
		var level_name = $("#member_level").val();
		var tel = $("#telephone").val();
		var email = $("#member_email").val();
		var sex = $("input[name='sex']:checked").val();
		var status = $("input[name='status']:checked").val();
		
		if (username == '') {
			showTip('用户名不能为空','warning');
			return;
		}
		
		if(!checkUserName(username)){
			showTip('用户名已存在','warning');
			return;
		}

		if (password == null || password.length < 6) {
			showTip('密码必须不小于6位！','warning');
			return;
		}
		if(tel.length > 0){
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){ 
				showTip("手机号码有误，请重填",'warning');
				return; 
			}
		}
		if(email.length > 0){
			if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){ 
				showTip('邮箱错误,请重填','warning');
				return; 
			}
		}
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/addmember')}",
			data : {
				'username' : username,
				'nickname' :nickname,
				'password' : password,
				'level_name' : level_name,
				'tel' : tel,
				'email' : email,
				'sex' : sex,
				'status' : status
			},
			success : function(data) {
				if (data['code'] > 0) {
					showTip(data['message'],'success');
					$("#add_user").modal("hide");
					LoadingInfo(getCurrentIndex(1,'#productTbody'));
				} else {
					showTip(data['message'],'error');
					flag = false;
				}
			}
		});
			
	}
	//修改会员弹出
	function modify_user(uid){
		var id = parseInt(uid);
		$("#modify_user").modal("show");
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/getmemberdetail')}",
			data : { 'uid':id, },
			success : function(data) {
				$("#modify_uid").val(data.uid);
				if(data['user_name']!=''){
					$("#modify_username").val(data.user_name);
					$("#modify_username").attr('disabled',true);
				}
				$("#modify_nickname").val(data.nick_name);
				//$("#modify_password").val(data.user_password);
				$("#modify_username_hidden").val(data.user_name);
				$("#modify_telephone").val(data.user_tel);
				$("#modify_member_email").val(data.user_email);
				$("#modify_member_level").find("option[value="+data.member.member_level+"]").attr("selected",true);
				$("#sex").find("input[value="+data.sex+"]").attr("checked",true);
				$("#status").find("input[value="+data.user_status+"]").attr("checked",true);
			}
		});
	}
	/**
	重置密码弹出
	*/
	function modify_password(uid){
		$("#modify_password").modal("show");
		$("#modify_userid").val(uid);
	}
	/**
	修改密码提交
	*/
	function modifypassword(){
		var uid = $("#modify_userid").val();
		var password = $("#modify_passwords").val(); 
		if (password == null || password.length < 6) {
			showTip('密码必须不小于6位！','warning');
			return false;
		}
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/updatememberpassword')}",
			data : {
				'uid':uid,
				'user_password' :password
			},
			success : function(data) {
				if (data['code'] > 0) {
					showTip('修改成功','success');
					LoadingInfo(getCurrentIndex(uid,'#productTbody'));
					$("#modify_password").modal("hide");
				} else {
					showTip('修改失败','error');
					flag = false;
				}
			}
		});
	}
	
	
	function delete_user(uid){
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/member/deletemember')}",
						data : { "uid" : uid.toString() },
						dataType : "json",
						success : function(data) {
							if(data["code"] > 0 ){
								LoadingInfo(getCurrentIndex(uid.toString(),'#productTbody'));
								showTip(data["message"],'success');
								$("#chek_all").prop("checked", false);
							}else{
								showTip(data["message"],'error');
							}
						}
					});
					$(this).dialog('close');
				},
				"取消,#e57373": function() {
					$(this).dialog('close');
				},
			},
			contentText:"删除会员同时会删除会员相关账户信息，确定要删除吗？",
		});
	}
// 	//修改会员
	function modifyUser(){
		var uid = $("#modify_uid").val();
		var username = $("#modify_username").val();
		var nickname = $("#modify_nickname").val();
		var tel = $("#modify_telephone").val();
		var email = $("#modify_member_email").val();
		var level_name = $("#modify_member_level").val();
		var sex = $("input[name='sex']:checked").val();
		var status = $("input[name='status']:checked").val();
			
		 if(tel.length > 0){
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){ 
				showTip("手机号码有误，请重填",'warning');
				return false; 
			}
		}
		 if(email.length > 0){
			if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){ 
				showTip('邮箱错误,请重填','warning');
				return false; 
			}
		}
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/member/updatemember')}",
			data : {
				'uid':uid,
				'user_name' :username,
				'nick_name' : nickname,
				'level_name' : level_name,
				'tel' : tel,
				'email' : email,
				'sex' : sex,
				'status' : status
			},
			success : function(data) {
				if (data['code'] > 0) {
					showTip(data['message'],'success');
					LoadingInfo(getCurrentIndex(uid,'#productTbody'));
					$("#modify_user").modal("hide");
				} else {
					showTip(data['message'],'error');
					flag = false;
				}
			}
		});
	}
	//批量删除
	function batchDelete() {
		var uid= new Array();
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				uid.push($(this).val());
			}
		});
		if(uid.length ==0){
			$( "#dialog" ).dialog({
				buttons: {
					"确定,#e57373": function() {
						$(this).dialog('close');
					}
				},
				contentText:"请选择需要操作的记录",
				title:"消息提醒",
			});
			return false;
		}
		delete_user(uid);
	}
	/**
	 * 会员数据导出
	 */
	function dataExcel(){
		var search_text = $("#search_text").val();
		var levelid = $("#level_name").val();
		window.location.href=__URL("ADMIN_MAIN/member/memberDataExcel?search_text="+search_text+"&levelid="+levelid); 	
	}
</script>
{/block}